home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / sources.arc / DANG_SRC.LZH / ENC2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  26.7 KB  |  1,006 lines

  1. #include<osbind.h>
  2.  
  3. #include<globals2.h>
  4. #define    Setpalette(a)    xbios(6,a)
  5.  
  6. char parry[] = "2 klang";                 /* that -q disables intro mssg on play.ttp */
  7.                                          /* but i call it 'player' */
  8. char miss[]  = "2 swish";   
  9. char CRY[]   = "2 cry11";
  10. char CAST[]  = "2 cast1";
  11. char enc_intro[] = "2 encou";
  12. char engarde[]="2 engar";
  13. char explode[]="2 explo";
  14. char hit_em[] = "2 hit00";
  15.  
  16. /*This module has all the fight routines, it will call:
  17.  
  18.                        a hell-of-a lot of subroutines, all
  19.                        of which are inside this module....
  20.                                                             */
  21. encounter(mf_src,mf_dest,pxyarray,scr6,run)
  22. register MFDB *mf_src,*mf_dest;   /* the src and dest MFDBs!! */
  23. char *scr6;  /* addr of misc3.dat has monster/chest pic */
  24. int pxyarray[8],*run;
  25.           
  26. {
  27.  int f;
  28.  char command;
  29.  int s_ave[8];
  30.  char clkj; 
  31.  
  32.  /* quickly reset pxyarray dest coords */
  33.     pxyarray[4] = 194; /* just reset the x1 and x2 values */
  34.     pxyarray[6] = 316; /* new pic code may have reset dest values.. */
  35.  
  36.  
  37.   /* load up pic for monster */
  38.    for(f=0;f<8;f++) s_ave[f] = pxyarray[f]; /*save array */
  39.             mf_src->fd_addr = (long) scr6; /* copy address */
  40.    
  41.                  /* set up dest for mask */
  42.       pxyarray[4] = 224;  
  43.       pxyarray[5] = 4;         /* dest */
  44.       pxyarray[6] = 289;  
  45.       pxyarray[7] = 90;  /* was 94 */ 
  46.  
  47.       pxyarray[0] = 2;
  48.       pxyarray[1] = 94;      /* source */
  49.       pxyarray[2] = 67;
  50.       pxyarray[3] = 180; 
  51.               /* lets replace color (0x330) in pen # 10 to black */
  52.        Setcolor(10,0x000);      
  53.        vro_cpyfm(handle,4,pxyarray,mf_src,mf_dest); /* !S & D */
  54.        /* mask uses color register 16 or 1111 binary 
  55.           NOT 1111 = 0000 ,  AND this with the DEST leaves a black 
  56.           siluette */
  57.  
  58.                         /* coords of the actual image to copy after we masked */
  59.       pxyarray[0] = 105;      /* x's 106,180 */
  60.       pxyarray[1] = 94;  /* get the src rectangle */
  61.       pxyarray[2] = 170;     /* was 171 */
  62.       pxyarray[3] = 180; 
  63.       
  64.            vro_cpyfm(handle,7,pxyarray,mf_src,mf_dest);
  65.  
  66.  
  67.        invoke_tsr( enc_intro );
  68.  
  69.     /* restore the dest coords */
  70.       for(f=4;f<8;f++) pxyarray[f] = s_ave[f]; /* restore dest */
  71.  
  72. command = Bconin(2);
  73.  
  74.  
  75.  runner = 1;
  76.  mon_num = 1; 
  77.  mon_alive = 1;   /* set tjis = to 1 */
  78.  char_alive = 1;  /* you're alive */
  79.  lvl_monsters(run);            /* gets monster type */
  80.  
  81.  
  82. v_gtext(handle,197,99,"              ");  /* clear mssg area */
  83. v_gtext(handle,197,99,mon.name);
  84.  clear_it();
  85.  amount();                  /* gets amount*/
  86.   surprise();                /* who goes first?*/
  87.   if(who_goes == 0)
  88.    {                                                 
  89.      v_gtext(handle,6,19,"You are surprised!!");
  90.      
  91.      pause();
  92.      mon_attack();
  93.    }
  94.    if(who_goes ==1)
  95.    {
  96.      
  97.      sprintf(string,"You surprise %d",mon_num);
  98.      v_gtext(handle,6,19,string);
  99.      v_gtext(handle,6,35,mon.name);
  100.      pause();
  101.      char_attack();
  102.      
  103.    }
  104.  alive();                         /* check to see if anyone's alive*/
  105.  
  106.   while(char_alive ==1 && runner ==1 && mon_num !=0)
  107.   /* ok, this says that IT WILL execute if:
  108.                
  109.                the character is still alive
  110.                the character hasnt not run away 
  111.         and... if there are still monsters to fight  */
  112.     {
  113.        display_user_stats();
  114.  
  115.      if(char_alive ==1)           /* well, user always goes 1st here*/
  116.      {
  117.       char_attack();
  118.        alive();
  119.      if(mon_alive ==0 && mon_num !=0) next_monster();  /* inits next monster
  120.                                         and sets mon_alive == 1 */
  121.     
  122.     }
  123.      if(mon_alive ==1 && mon_num !=0) 
  124.                         /* last but not least, the monster. This 
  125.                            will exec. if the moster is still alive,
  126.                            AND you didnt just kill a monster */
  127.      {
  128.       mon_attack();
  129.      alive();
  130.       }
  131.     }               /* You will only get treasure if ALL monsters
  132.                        have been killed */ 
  133.    clear_it();
  134.    if(char_alive ==0) cool_effect();  /* you died */
  135.                                      /* for mon_alive to be 0, ALL*/
  136.  
  137.     
  138.   f=0;
  139.    if(mon_alive ==0) f=treasure();       /* monsters must have been killed*/
  140.       if (f)
  141.         {
  142.          /* load up chest pic!, since mf_src already points to MISC3.DAT
  143.        (because it loaded up the monster pic) the chest pic is also
  144.        in MISC3.DAT, so just set new source coords and copy!  */
  145.       pxyarray[0] = 194;
  146.       pxyarray[1] = 3;  /* get the src rectangle */
  147.       pxyarray[2] = 316;
  148.       pxyarray[3] = 91; 
  149.       
  150.        vro_cpyfm(handle,3,pxyarray,mf_src,mf_dest);
  151.  
  152.      v_gtext(handle,6,27,"You found a chest.     ");
  153.      
  154.   /* ask if you will open/pick it, etc. It will contain potions, */
  155.   /* jewels, weapons, maps, etc.!! */
  156.      
  157.     
  158. v_gtext(handle,197,99,"     Chest    ");
  159.  
  160.     
  161.     v_gtext(handle,6,41," Will you :          ");
  162.     
  163.     v_gtext(handle,6,49,"   O - Open it. ");
  164.     v_gtext(handle,6,57,"   L - Leave it alone");
  165.     v_gtext(handle,6,65,"                     ");
  166.     v_gtext(handle,6,81,"   Thy choice : ");
  167.    do
  168.      { command = Bconin(2);
  169.      }while(command != 'o' && command!= 'O' && command !='l' && command!= 'L');
  170.    
  171.   switch(command)
  172.       {
  173.          case 'O':
  174.          case 'o':
  175.                   open_chest();
  176.                   break;
  177.       }
  178. clear_it();
  179.  
  180.     
  181.     
  182.  
  183.         }
  184.  
  185.  
  186. /* re-play sound if there was sound playing before encounter */
  187. if(CURRENT_SOUND == 1) Dosound( wind_sound );
  188.  
  189. if(CURRENT_SOUND == 4) Dosound( rain_sound );
  190.  
  191. if (runner ==0) *run =1;  
  192.  else *run=0;    /* say you ran! */
  193.  
  194. for(f=0;f<8;f++)  pxyarray[f] = s_ave[f]; /*restore array */
  195. display_user_stats();
  196.  
  197.  
  198. while ( (Bconstat(2)) == -1) clkj = Bconin(2);  /* clear out keyboard buf */
  199.  
  200.   /* lets replace color (0x000) in pen # 10 to color 0x330 */
  201.        Setcolor(10,0x330);      
  202.  
  203. }      /* end of encounter! */
  204.  
  205.  
  206.  
  207. /***********************************/
  208.  
  209.  
  210. /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
  211.  
  212. char_attack()
  213.  
  214. {
  215.   int good,ret;
  216.   char comm;
  217.   
  218. good =0;                    /* good is set to 1, if user input is valid*/
  219.  
  220. clear_it();
  221. v_gtext(handle,6,11,"    ~ Fight Options ~  ");
  222. v_gtext(handle,6,27,"(F)ight             ");
  223. v_gtext(handle,6,35,"(C)ast a spell      ");
  224. v_gtext(handle,6,43,"C(h)arm Monster     ");
  225. v_gtext(handle,6,51,"(B)attle Cry        ");
  226. v_gtext(handle,6,59,"(R)un               ");
  227. v_gtext(handle,6,67,"(S)ound On/Off      ");
  228. do
  229. {
  230.  comm=Bconin(2);       /* get input from keyboard*/
  231.  
  232.  switch(comm)
  233.     {
  234.      case 'H':
  235.      case 'h': Charm_monster();good=1;      break;
  236.      case 'F':
  237.      case 'f': fight();
  238.                good = 1;
  239.                break;
  240.      case 'C': 
  241.      case 'c': ret=cast();
  242.                good=1;
  243.                pause();
  244.                break;
  245.      case 'S': 
  246.      case 's': sound_turnage();
  247.                good=0;   /* since just a game option, dont count it as a move */
  248.                 break;
  249.      case 'R': 
  250.      case 'r': run();
  251.                good=1;
  252.                break;
  253.      case 'B':
  254.      case 'b': battle_cry();
  255.                good=0;  /* game option, no move */
  256.                break;
  257.          }     /* end of switch*/
  258.  }            /* end of do*/
  259.  while(good==0) ;          /*good is set to 0 before case, if =0*/
  260.                            /* then users choice wasnt valid */
  261. clear_it();
  262.  
  263. } /* end of char attack */
  264.  
  265.  
  266. /****************************************/
  267. battle_cry()
  268. {
  269.  
  270.   invoke_tsr( CRY );
  271.  
  272. }
  273. /****************************************************/
  274. /***********/
  275.  Charm_monster()
  276. {
  277.  int hit,hld_exp;
  278.  
  279.  clear_it();
  280.  hit = rnd(100); hit+=18;  /* lower limit will be 18 */
  281.  if( (user.con + (user.current_spells_active[4]*5)) >= hit)
  282.  {
  283.   v_gtext(handle,6,11,"You charmed it!!");
  284.    
  285.         hld_exp = (mon_lvl+1*4)+(mon.hd*4)+ mon.spell+mon.weapon;
  286.         
  287.         user.exp +=hld_exp;
  288.         mon_num--;            /* subt 1 from # of monsters!*/
  289.         if(mon_num !=0)
  290.           {
  291.            sprintf(string,"You face %d more monsters  ",mon_num);
  292.            v_justified(handle,6,27,string,184,0,1);
  293.            pause();
  294.           }
  295.        if(mon_num == 0){v_gtext(handle,6,27,"You've defeated all the");
  296.                         v_gtext(handle,6,35,"monsters...");
  297.                          pause();
  298.                          mon_alive=0;  /* all monsters dead.. */
  299.                        }
  300.      }
  301.    else 
  302.     v_gtext(handle,6,11,"The monster growls..");
  303.     pause();
  304. }
  305. /***********/
  306. fight()
  307. {
  308.   
  309.   int temp_dex,temp_str,temp_mon,hit,damage,range,hld_exp;
  310.   int m_o_p; /*missed or blow parried a random number */ 
  311.  
  312.   clear_it();
  313.   temp_dex = user.dex -18;                /* if dex >18, difference is */
  314.   if(temp_dex < 0) temp_dex =0;      /* a bonus, same with STR*/
  315.   temp_str = user.str -18;
  316.   if(temp_str < 0) temp_str =0;
  317.   temp_mon = mon_num;
  318.  
  319.   hit =abs(rnd(19));                     /* roll a dice*/
  320.   hit++;                      /* add 1 to it, makes it a 1d20*/
  321.   hit +=temp_dex;              /*add bonus*/
  322.    
  323.  
  324.  
  325.  
  326.  if(hit < hrt[mon.ac])  /* else check for miss */
  327.    {
  328.     hit=0;
  329.    }
  330. else hit = 1;
  331.   if (hit ==0)                  /* hit is set by the HRT(above code) */
  332.  {
  333.  m_o_p = rnd(2);
  334.  switch (m_o_p)
  335.    {
  336.    case 0:
  337.           invoke_tsr( parry );
  338.           v_gtext(handle,6,13,"your blow is parried  ");
  339.           break;
  340.    case 1:
  341.           invoke_tsr( miss );
  342.           v_gtext(handle,6,13,"you missed            ");
  343.           break;
  344.    }
  345.  pause();
  346.  }
  347.   if (hit ==1)                      /* well, looks like we hit em eh?*/
  348.  {     /*begin of hit 1*/
  349.   range = user.weapon_num;
  350.   damage = abs(rnd(range));         /* get damage*/
  351.   damage++;
  352.   damage = damage+temp_str +1;             /* add bonus and +1*/
  353.   damage +=user.current_spells_active[3]*5; /* add 5 point bouns if you 
  354.                                           have magical strength! */
  355.  
  356.   mon.hp = mon.hp - damage;         /* subt. from monster hp*/
  357.    invoke_tsr( hit_em );
  358.    v_gtext(handle,6,13,"You hit the");
  359.     sprintf(string,"%s and..",mon.name);
  360.   v_gtext(handle,6,21,string);
  361.   if(mon.hp<1)           /* if no more hp, then he must be dead!*/
  362.     {                
  363.         v_gtext(handle,6,29,"it lets out a piercing");
  364.         v_gtext(handle,6,37,"shreak as it slumps to");
  365.         v_gtext(handle,6,45,"the ground.");
  366.         pause();
  367.         
  368.        
  369.    hld_exp = (mon_lvl+1*4)+(mon.hd*4)+ mon.spell+mon.weapon;
  370.      
  371.         user.exp +=hld_exp;
  372.         mon_num--;            /* subt 1 from # of monsters!*/
  373.         if(mon_num !=0)
  374.           {
  375.            sprintf(string,"You face %d more monsters  ",mon_num);
  376.            v_justified(handle,6,69,string,184,0,1);
  377.            pause();
  378.           }
  379.     }
  380.   if(mon.hp>0)
  381.          {
  382.          sprintf(string,"it takes %d points damage! ",damage);
  383.          v_justified(handle,6,29,string,184,0,1);
  384.          pause();
  385.          }  
  386.   if(mon_num ==0)
  387.          {
  388.          v_gtext(handle,6,61,"You have defeated all ");
  389.          v_gtext(handle,6,69,"the monsters. ");
  390.          pause();
  391.          mon_alive =0;      /* if all are dead, set mon_alive to 0 */
  392.          }
  393.   
  394.   } /*end of hit 1 */
  395.   }     /* end of fight*/
  396.  
  397.  
  398.  
  399.  
  400.  
  401. /*********/
  402. cast()             /* oooh spellcasters...my favorite */
  403.  
  404. {
  405.   char commandc; 
  406.   int temp_inte,temp_wis,temp_mon,hit,damage,range,dummy;
  407.   int max_spell_num,x,commandi;
  408.   char sp[26];  
  409.   int hld_exp;
  410.  
  411.  clear_it();
  412.   max_spell_num = 2*user.lvl;
  413.   
  414.   /* max_spell num to cast = users lvl! */
  415.   dummy =0;
  416.    /* calculate lvl to cast spells. Formula:  */
  417.    /* user.lvl*2 = max spell number you can cast*/ 
  418.   v_gtext(handle,6,11,"Cast what spell? ");
  419.   sprintf(string,"[1-%d] or e(X)it ",max_spell_num); 
  420.   v_gtext(handle,6,19,string);
  421.   do
  422.   {
  423.   commandc=Bconin(2);       /*get input*/
  424.   commandi = commandc - '0'; /* get int value, only 0-9 right now */
  425.   if (commandi == 0 ) commandi =999;
  426.   }while((( commandi > max_spell_num) || (commandi > user.sp)) && (commandc !='x' && commandc !='X')); 
  427.   
  428. if(commandc == 'X' || commandc == 'x') 
  429.  return;
  430.  
  431.  else       /*if command = 999 the dont execute! */
  432.   { 
  433.    
  434.   user.sp = user.sp - commandi; /*subtract sp*/
  435.   user.spell_num = commandi; /*set spell number into user stats*/
  436.   /* call module to convert spell 1 to a spell name and print the name */
  437.   conv_spell( commandi,sp );
  438.   clear_it();
  439.   v_gtext(handle,6,11,"You cast a");
  440.   v_gtext(handle,6,19,sp); 
  441.  
  442.   invoke_tsr( CAST );
  443.  
  444. temp_inte = user.inte -18;                /* if dex >18, difference is */
  445.   if(temp_inte < 0) temp_inte =0;      /* a bonus, same with STR*/
  446.   temp_wis = user.wis -18;
  447.   if(temp_wis < 0) temp_wis =0;
  448.   temp_mon = mon_num;
  449.  
  450.   hit = rnd(19);                     /* roll a 1d19*/
  451.   hit = hit +1;                      /* add 1 to it, makes it a 1d20*/
  452.   hit = hit + temp_wis;              /*add bonus*/
  453.  
  454.  if(hit >= hrt[mon.ac]) /* if roll is good, then set hit to 1*/
  455.     hit =1;
  456.  
  457.  else  /* else  miss */
  458.     hit=0;
  459.  
  460.   if (hit ==0)                  /* hit is set by the HRT(above code) */
  461.  {
  462.   v_gtext(handle,6,27,"it fizzes at your");
  463.   v_gtext(handle,6,35,"fingertips! ");
  464.   
  465.  }
  466.   if (hit ==1)                      /* well, looks like we hit em eh?*/
  467.  {     /*begin of hit 1*/
  468.   range = user.spell_num;
  469.   range = range + user.lvl; /*add lvl bonus to range*/
  470.   damage = rnd(range);         /* get damage*/
  471.   damage = user.inte +1;             /* add bonus and +1*/
  472.   damage = abs(damage);
  473.   mon.hp = mon.hp - damage;         /* subt. from monster hp*/
  474.   v_gtext(handle,6,27,"it strikes the fiend!");
  475.   invoke_tsr( explode );  /* boom!! */
  476.   if(mon.hp<1)           /* if no more hp, then he must be dead!*/
  477.     {                
  478.         v_gtext(handle,6,35,"The monster falls to ");
  479.         v_gtext(handle,6,43,"the ground, blood gush-");
  480.         v_gtext(handle,6,51,"ing from its wounds!!!");
  481.       
  482.     hld_exp = (mon_lvl+1*4)+(mon.hd*4)+ mon.spell+mon.weapon;
  483.     user.exp +=hld_exp;  
  484.         mon_num--;            /* subt 1 from 3 of monsters!*/
  485.         if(mon_num !=0)
  486.           {
  487.            sprintf(string,"You still face %d more ",mon_num);
  488.            v_gtext(handle,6,67,string);
  489.            v_gtext(handle,6,75,"monsters(s)");
  490.            for(hit=0;hit<999;hit++)
  491.            {
  492.      }
  493.     }  /* end of if hit == 1 */
  494.     }
  495.   if(mon.hp>0)
  496.          {
  497.          sprintf(string,"it takes %d pts ",damage);
  498.          v_gtext(handle,6,35,string);
  499.          v_gtext(handle,6,43,"damage!!");
  500.          }
  501.   if(mon_num ==0)
  502.          {
  503.          v_gtext(handle,6,67,"You've defeated all the");
  504.          v_gtext(handle,6,75,"monsters.");
  505.          mon_alive =0;      /* if all are dead, set mon_alive to 0 */
  506.          for(hit=0;hit<999;hit++)
  507.           {
  508.            }
  509.          }
  510.    
  511.   } /*end of hit 1 */
  512.   
  513. } /*end of if command != 999*/
  514.  
  515.  
  516.  
  517. } /*end of cast */
  518.  
  519.  
  520. /********/
  521. sound_turnage()
  522. {
  523. int mask = 1;
  524.  
  525.  
  526.  
  527.    /* sound on-off */
  528.   
  529.     if(sound == 1) v_gtext(handle,6,83,"   Sound is now OFF   ");
  530.     else v_gtext(handle,6,83,"   Sound is now ON    ");
  531.     sound ^= mask;   /* xor with mask */ 
  532.    
  533. }
  534.  
  535. /******/
  536. run()
  537. {
  538.   int run_ok;
  539.  
  540.   clear_it();
  541.  run_ok= rnd(50);
  542.  if(user.current_spells_active[1]) run_ok =1; /* if you have fleetness. you always get away..*/
  543.   if(run_ok <=24)
  544.    {
  545.      v_gtext(handle,6,19,"You got away!!!       ");
  546.     
  547.      runner=0;
  548.     
  549.     } 
  550.  if (run_ok >24)
  551.      v_gtext(handle,6,19,"You didn't get away.  ");
  552.  
  553.  
  554.       pause();
  555.  
  556. }
  557.  
  558.  
  559.  
  560.  
  561. /******************************************************/
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568. /******************/
  569. lvl_monsters(run)
  570. int *run;
  571. {
  572. char command;
  573.  
  574.  if(user.lvl ==1)
  575.    mon_lvl =1;
  576.  if(user.lvl >1)
  577.    {
  578.     mon_lvl = rnd(user.lvl);
  579.     if(mon_lvl ==0)
  580.       mon_lvl++;
  581.    }
  582.   if( *run == -999) mon_lvl = 47;  /* if *run = -999 set monster to Demon lord */
  583.   
  584. /*actually get the monster*/
  585.  
  586. strcpy(mon.name,monsters[mon_lvl].name);             /*monsters[mon_lvl].name;*/
  587.  
  588. mon.ac    = monsters[mon_lvl].ac;       /*monsters[mon_lvl].ac;*/
  589. mon.hd    = monsters[mon_lvl].hd;          /*monsters[mon_lvl].hd;*/
  590. mon.hp    = monsters[mon_lvl].hp;         /*monsters[mon_lvl].hp;*/
  591. mon.weapon= monsters[mon_lvl].weapon;        /*monsters[mon_lvl].weapon;*/
  592. mon.spell = monsters[mon_lvl].spell;       /*monsters[mon_lvl].spell;*/
  593. mon.lvl   = monsters[mon_lvl].lvl;
  594.  
  595. }
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608. /***********/
  609.  
  610. amount()
  611. {
  612.    int range;
  613. char command;
  614.   
  615.  
  616.   range = user.lvl;
  617.   mon_num = rnd(range);
  618.  
  619.   if(mon_num ==0) 
  620.        mon_num++;
  621.  
  622.    mon_num = abs(mon_num);
  623.  
  624.  }
  625.  
  626.  
  627. /*************/
  628.  
  629. surprise()
  630. {
  631.    int char_roll;
  632.    int mon_roll;
  633.  
  634.  
  635.  
  636.  char_roll = rnd(6);
  637.  mon_roll  = rnd(6);
  638.  
  639.  if (char_roll >= mon_roll)
  640.     who_goes =1;         /* means character goes first */
  641.  if( char_roll < mon_roll)
  642.     who_goes =0;
  643. }
  644.  
  645. /*********************/
  646. alive()
  647. {
  648.  
  649.  if(mon.hp <=0)
  650.       mon_alive =0;
  651.    
  652.      
  653.  if (user.hp <=0)     
  654.       char_alive =0;
  655.      
  656.  }
  657.  
  658.  
  659.  
  660. /*******************************/
  661.  
  662. treasure()
  663.  
  664.   /* allocates exp and gld and items */
  665.  {
  666.    int  temp_gld;
  667.    int  roller;   
  668.    char command;
  669.    
  670.  
  671. if(runner == 1)   /* if you have not run away */
  672.  {   
  673.   v_gtext(handle,197,99,"   Treasure   ");
  674.    clear_it();
  675.    roll_gold(user.lvl,user.con,mon.lvl);
  676.    roller = rnd(600);
  677.    if(user.current_spells_active[0]) roller +=550; /* gives you an 86% chance
  678.                                                  to find a chest.. if you have treasure finding!!!*/
  679.    if(roller > 590)
  680.      return 1;   /* chest!! */
  681.     else return 0;
  682.   } 
  683. }       
  684.  
  685. /*******************************/
  686.  open_chest()
  687.  {
  688.   char comm;
  689.   int k,roll,temp_dex,user_roll,troll,examine;
  690.   int good;
  691.    
  692.    clear_it();
  693.    good = 0; /* if 0, invalid option chosen */
  694.    examine =0;  /* if set to 1, then a trap was found */   
  695.  do
  696.  {
  697.    v_gtext(handle,6,19,"Will you :        ");
  698.    v_gtext(handle,6,27,"  O - Open it   ");
  699.    v_gtext(handle,6,35,"  E - Examine it");
  700.    v_gtext(handle,6,43,"  C - Cast spell");
  701.    v_gtext(handle,6,51,"  L - Leave it  ");
  702.    v_gtext(handle,6,59,"                ");
  703.    v_gtext(handle,6,67,"                ");
  704.    v_gtext(handle,6,74,"                ");
  705.   
  706.    comm = Bconin(2);    
  707.   
  708.    clear_it();
  709.    switch(comm)
  710.     {
  711.       case 'o':
  712.       case 'O':good =1;
  713.              if(examine == 1)
  714.               {
  715.                roll_gold(user.lvl*100,user.con,mon.lvl);
  716.               }
  717.              else
  718.              {          
  719.                  
  720.                roll = rnd(18);
  721.                user_roll = rnd(15);
  722.                temp_dex = user.dex - 18;
  723.                if(temp_dex <0) temp_dex =0;
  724.                user_roll = user_roll + temp_dex;
  725.                  if(user_roll >= roll)
  726.                      {
  727.                          roll_gold(user.lvl*100,user.con,mon.lvl);
  728.                      }
  729.                  if(user_roll < roll)
  730.                      {
  731.                       roll = rnd(3);
  732.                  if(roll ==1) v_gtext(handle,6,19,"Nothing happens");
  733.                  if(roll ==2)
  734.                      {
  735.                      v_gtext(handle,6,27,"You trigger a trap");
  736.                      roll = rnd(user.lvl+5);
  737.                      sprintf(string,"and take %d pts damage",roll);
  738.                      v_gtext(handle,6,35,string);
  739.                      } 
  740.                     }
  741.                }  /* end of else*/
  742.               break;
  743.             
  744.             
  745.       case 'e':
  746.       case 'E': /* dont set good =1 here */ 
  747.               good = 0;
  748.               roll = rnd(18);
  749.               user_roll = rnd(18);
  750.               temp_dex = user.dex -18;
  751.               if(temp_dex > 0)
  752.               {
  753.               user_roll = user_roll + temp_dex;
  754.               }
  755.               if(user_roll>=roll)
  756.               {
  757.                v_gtext(handle,6,19,"You found a trap!");
  758.                examine =1;   /* set flag to denote trap was found */
  759.               }
  760.               else 
  761.               v_gtext(handle,6,19,"You found nothing");
  762.              
  763.               break;
  764.       case 'c':
  765.       case 'C':good =0;        /* just checking..dont wanna exit yet! */
  766.                if( user.sp >= 3) user.sp = user.sp -3;
  767.                v_gtext(handle,6,19,"You cast a spell...");
  768.                if (user.sp < 3) 
  769.                  {
  770.                   v_gtext(handle,6,27,"Not enough sp");
  771.                   break;
  772.                  }
  773.                user.sp -= 3;       /*subt sp */ 
  774.                user_roll = rnd(35+user.lvl);
  775.                user_roll +=(user.wis-12);
  776.                if (user_roll > 27){ v_gtext(handle,6,27,"you found a trap!");examine=1;}
  777.               else v_gtext(handle,6,19,"You found nothing");
  778.                
  779.                break;
  780.       case 'l':
  781.       case 'L': good =1;
  782.       
  783.   } /* end of switch */
  784.  pause();
  785.  clear_it();
  786.   } /* end of do while */
  787.    while(good == 0);
  788.  
  789.  
  790.   
  791.  }     /* end of module*/
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798. /**********************************************************/
  799.    /* monster attack */
  800.  
  801.  mon_attack()
  802.   {
  803.    
  804.     /* use A.I. to decide if the monster will attack, talk or run */
  805.     /* if attacking, decide if it will fight or cast. */
  806.     int mstr;
  807.     int mhit,mdamage;
  808.     int mop; /* miss or parry.. */
  809. clear_it();
  810.  
  811.  
  812.   mhit = rnd(20);                     /* roll a 1d20*/
  813.   mhit++;                      /* add 1 to it, makes it a 1d20*/
  814.  mhit = mhit + mon.hd; /* add monsters hit dice to it */
  815.  if(mhit >= mhrt[user.ac]) /* if roll is good, then set hit to 1*/
  816.    {
  817.     mhit =1;
  818.    }
  819.  
  820.    else mhit = 0;
  821.  
  822.   if (mhit ==0)                  /* hit is set by the HRT(above code) */
  823.  {
  824.   mop = rnd(2);
  825.   if ( mop == 0 )
  826.   {
  827.   v_gtext(handle,6,19,"The monster missed!    ");
  828.   invoke_tsr( miss );                         
  829.   }
  830.  else 
  831.    { 
  832.      v_gtext(handle,6,19,"You parry the blow!    ");
  833.      invoke_tsr( parry );
  834.    }
  835.   pause();
  836.  } 
  837.  if (mhit ==1)                      /* well, looks like we hit em eh?*/
  838.  {     /*begin of hit 1*/
  839.   mdamage = abs(rnd(mon.weapon));         /* get damage*/
  840.   mdamage +=mon.spell;
  841.   
  842.   mdamage -=(user.lvl*user.current_spells_active[2]); /* subtract 1 from danage if you 
  843.                                          have Protection.. */
  844.   if(mdamage < 1) mdamage = 1;
  845.   user.hp = user.hp - mdamage;         /* subt. from user hp*/
  846.  
  847.   invoke_tsr( hit_em );
  848.   v_gtext(handle,6,19,"The monster hits you");
  849.   if(user.hp<1)           /* if no more hp, then he must be dead!*/
  850.     {                
  851.      v_gtext(handle,6,27,"and you choke on your");
  852.      v_gtext(handle,6,35,"own blood and sink to");
  853.      v_gtext(handle,6,43,"the floor...");
  854.      pause();  
  855.     }
  856.   if(user.hp>0)
  857.       {
  858.          sprintf(string,"You take %d points",mdamage);
  859.          v_gtext(handle,6,27,string);
  860.          v_gtext(handle,6,35,"damage!!");
  861.          pause();
  862.        }
  863.   } /*end of hit 1 */
  864.   }     /* end of mon attack*/
  865.  
  866.  
  867. /*********************************************************/
  868. /* the infamous PAUSE() function */
  869.  
  870. pause()
  871. {
  872.   char ts;
  873.  
  874.     ts = Bconin(2);
  875. }
  876.  
  877. /*****/
  878.  
  879. clear_it()
  880. {
  881. v_gtext(handle,6,8,"                       ");
  882. v_gtext(handle,6,13,"                       ");
  883. v_gtext(handle,6,19,"                       ");
  884. v_gtext(handle,6,25,"                       ");
  885. v_gtext(handle,6,31,"                       ");
  886. v_gtext(handle,6,37,"                       ");
  887. v_gtext(handle,6,43,"                       ");
  888. v_gtext(handle,6,49,"                       ");
  889. v_gtext(handle,6,55,"                       ");
  890. v_gtext(handle,6,61,"                       ");
  891. v_gtext(handle,6,67,"                       ");
  892. v_gtext(handle,6,73,"                       ");
  893. v_gtext(handle,6,79,"                       ");
  894. v_gtext(handle,6,85,"                       ");
  895. }
  896. /**********************************/
  897. /* Rolls gold, the users level is sent, and so is his con
  898.    also mon lvl is sent 
  899.  
  900.  
  901.    Also:
  902.     o    Rolls for Gems/Jewels
  903.     o    Potions!
  904.  
  905. */
  906.  
  907. roll_gold(lvl,con,mon_lvl)
  908. int lvl,con,mon_lvl;
  909. {
  910.  int troll,
  911.      extra=20,
  912.      conextra;
  913.                clear_it();
  914.                troll = rnd(5+con);
  915.                troll = abs(troll + lvl + mon_lvl);
  916.                sprintf(string,"You find %d gold!",troll);
  917.                v_gtext(handle,6,19,string);
  918.                user.gold = user.gold+troll;
  919.  
  920.                troll = abs(rnd(300));   
  921.                 /* usually you have a 10% chance of finding 
  922.                    gems/jewels/potions
  923.                    add your (CON-18) to it
  924.                 */
  925.              if(user.current_spells_active[0]) troll -=user.con; /* big bonus. */ 
  926.              conextra = user.con - 18;
  927.              if(conextra < 0 ) conextra =0;
  928.              troll -=conextra; /* bonus */      
  929.              
  930.                 if( troll < 10 )   /* extra special items found!! */
  931.                  {
  932.                  troll = abs(rnd(3));
  933.                  switch(troll) 
  934.                   {
  935.                   case 0: v_gtext(handle,6,27,"You found a Jewel!!");
  936.                           user.user_items[5]++; break;
  937.                   case 1: v_gtext(handle,6,27,"You found a Gem!!");
  938.                           user.user_items[4]++; break;
  939.                   case 2: v_gtext(handle,6,27,"You found a potion!");
  940.                           roll_for_potion(); break;
  941.                   }
  942.  
  943.                  } 
  944. }
  945.  
  946. /************************************************/
  947. /* returns a string of the form, "you cast a 'spellname' and.." 
  948. */
  949. conv_spell( s,sp )
  950. int s;
  951. char sp[];
  952.  
  953. {
  954.  
  955. if ( s == 1 )
  956.   strcpy(sp,"Magic Missle and..");
  957. if (s == 2)
  958.   strcpy(sp,"Wall of fire and..");
  959. if(s== 3)
  960.   strcpy(sp,"Fireball! and..");
  961.      
  962. if (s== 4)
  963.    strcpy(sp,"Lightning bolt and..");
  964.            
  965. if (s == 5)
  966.     strcpy(sp,"Magic darts and..");
  967.       
  968. if (s == 6)
  969.     strcpy(sp,"Greater Havoc and..");
  970.   
  971.     
  972. }
  973. /************************************************/
  974.  
  975. /**
  976.    Roll for potion
  977. **/
  978.  
  979. roll_for_potion()
  980. {
  981.   int troll;
  982.   
  983.   troll = abs(rnd(8));
  984.   troll +=6;   /* offset to get in range of potions. Ie if roll 0
  985.                   the add 6 to it, so you get potion1 which is 
  986.                   at cell 6 of user_items[] */
  987.   user.user_items[troll]++;
  988. }
  989.  
  990.  
  991. /***/
  992. next_monster()
  993. {
  994. /*actually get the monster*/
  995.  
  996. strcpy(mon.name,monsters[mon_lvl].name);             /*monsters[mon_lvl].name;*/
  997. mon.ac    = monsters[mon_lvl].ac;       /*monsters[mon_lvl].ac;*/
  998. mon.hd    = monsters[mon_lvl].hd;          /*monsters[mon_lvl].hd;*/
  999. mon.hp    = monsters[mon_lvl].hp;         /*monsters[mon_lvl].hp;*/
  1000. mon.weapon= monsters[mon_lvl].weapon;        /*monsters[mon_lvl].weapon;*/
  1001. mon.spell = monsters[mon_lvl].spell;       /*monsters[mon_lvl].spell;*/
  1002. mon.lvl   = monsters[mon_lvl].lvl;
  1003. mon_alive = 1;
  1004.  
  1005. }
  1006.